
<?
	 layout("/inc/win_layout.html",{title:sysTitle}){
    ?>


<div class="panel ">
	<div class="panel-body pan" style="height: 305px">
	<div class="form-body pal">
		<div class="row" style="margin-top:-15px; margin-bottom: 10px;">
			<div class="col-lg-6"
				style="width: 400px; height: 60px;float:left;  margin-right:-20px; display:inline;">
				<label for="inputUsername" class="col-md-3 control-label">中文名称
					<span class='require' id="yonghu">*</span> </label>
				<div class="col-md-9">
					<div class="input-icon">
						<input id="nameZh" type="text" class="form-control" />
					</div>
				</div>
			</div>
			<div class="col-lg-6"
				style="width: 400px;height: 60px; float:left;  margin-right:-20px; display:inline;">
				<label for="inputUsername" class="col-md-3 control-label">英文名称
					<span class='require'>*</span> </label>
				<div class="col-md-9">
					<div class="input-icon">
						<input id="nameEn" type="text" class="form-control" />
					</div>
				</div>
			</div>
			<div class="col-lg-6"
				style="width: 400px;height: 60px; float:left; margin-right:-20px; display:inline;">
				<label for="inputUsername" class="col-md-3 control-label">所属领域<span
				class='require'>*</span> </label>
				<div class="col-md-9">
					<div class="input-group input-group-sm mbs">
						<input id="domainNmae" type="text" placeholder="请选择所属领域" class="form-control" disabled="true" /> 
						<span class="input-group-btn">
						<button onclick="geDomaint()" type="button" data-toggle="dropdown" class="btn btn-success dropdown-toggle">选择...</button>
						</span> 
						<input id="domainId" type="hidden" class="form-control" />
					</div>
				</div>
			</div>
			<div class="col-lg-6"
			 	style="width: 400px;height: 60px; float:left; margin-right:-20px; display:inline;">
				<label for="inputUsername" class="col-md-3 control-label">状态
				<span class='require'>*</span> </label>
				<div class="col-md-9">
					<div class="input-icon">
						<select id="status" class="form-control">
							<option value="0">正常</option>
							<option value="1">禁用</option>
						</select>
					</div>
				</div>
			</div>
			<div class="col-lg-6"
				style="width: 400px;height: 60px; float:left;  margin-right:-20px; display:inline;">
				<label for="inputUsername" class="col-md-3 control-label">排序
					<span class='require' >*</span> </label>
				<div class="col-md-9">
					<div class="input-icon">
						<input id="sort" type="text" class="form-control" />
					</div>
				</div>
			</div>
		</div>
		<div>
			<label for="inputUsername" class="col-md-3 control-label">描述
				<span class='require'></span> </label>
			<div class="col-md-12">
				<div class="input-icon">
					<textarea id="description"  rows="3" cols="20" class="form-control" ></textarea> 
				</div>
			</div>
		</div>
		<input id="id" type="hidden" class="form-control" />
	</div>
</div>
<?} ?>
<script>
	var id = window.parent.getId();
	var curr = window.parent.getCurr();
	$(function() {
		if (id != 0) {
			demo();
		}
	});
	//所属领域
	function geDomaint() {
		parent.layer.open({
			type : 2,
			area : ['900px', '650px'],
			fix : false, //不固定
			scrollbar : false,
			shadeClose : true,
			//move : false,
			title:"领域",
			skin : 'layui-layer-rim', //加上边框
			btn : [ '保存 ', '关闭' ],
			content : ["community-category-domain.html?winName="+window.name, 'no'],
			yes : function(index,layer) {		
			var iframeWin = parent.window[layer.find('iframe')[0]['name']];
			  			  iframeWin.save();
			},
			cancel : function(index) {
			}
		});
	}
	function Page() {
		if ($.trim($("#nameZh").val()).length < 1) {
			alert('中文名称不能为空！');
			return null;
		}
		if ($.trim($("#domainId").val()).length < 1) {
			alert('所属领域不能为空！');
			return null;
		}
		if ($.trim($("#nameEn").val()).length < 1) {
			alert('英文名称不能为空！');
			return null;
		}else{
			var reg = /^[a-zA-Z ]+$/;  
			    if (!reg.test($("#nameEn").val())) {  
			        alert('请输入正确的英文名称！');
			        $("#nameEn").val("");
					return null;
			    } 
		}
		if ($.trim($("#sort").val()).length < 1) {
			alert('排序不能为空！');
			return null;
		}else{
			 var reg = /^[0-9]*$/;  
			    if (!reg.test($("#sort").val())) {  
			        alert('排序只能为正整数！');
			        $("#sort").val("");
					return null;
			    }  
		}
		$.ajax({
			type : "post",
			url : "addOrUploadCommunityCategory.do",
			data : {
				"id" : id,
				"nameZh" : $("#nameZh").val(),
				"nameEn" : $("#nameEn").val(),
				"sort" : $("#sort").val(),
				"description" : $("#description").val(),
				"status" : $("#status").val(),
				"domainId" : $("#domainId").val(),
			},
			dataType : "json",
			async : false,
			success : function(data) {
				var index = parent.layer.getFrameIndex(window.name);
				if(data[0].data == 'yes'){
					window.parent.demo(curr);
					parent.layer.msg('提交成功');
					parent.layer.close(index);
				}else{
					parent.layer.msg('提交失败！请检查数据是否正确！');
				}
			},
			error : function(data) {
				parent.layer.msg('提交失败！请检查数据是否正确！');
			}
		});
	}
	function demo() {
		$.getJSON('findCommunityCategory.do', {
			id : id
		//向服务端传的参数，此处只是演示
		}, function(res) {
			//此处仅仅是为了演示变化的内容
			$("#nameZh").val(res[0].nameZh);
			$("#nameEn").val(res[0].nameEn);
			$("#description").val(res[0].description);
			$("#status").val(res[0].status);
			$("#sort").val(res[0].sort);
			$("#id").val(res[0].id);
			$("#domainNmae").val(res[0].domainName);
			$("#domainId").val(res[0].domainId);
		});
	};
</script>


